home *** CD-ROM | disk | FTP | other *** search
/ PC-SIG: World of Games / PC-SIG World of Games (CDRM1080710) (1993).iso / ENT / DISK1536.ZIP / TEMP.BAS < prev    next >
BASIC Source File  |  1990-02-26  |  18KB  |  457 lines

  1. SUB WriteVid INLINE
  2.   '
  3.   ' Move bytes to video memory preventing screen flicker and snow.
  4.   ' Turbo Basic calling sequence:
  5.   '   call WriteVid (NumBytes%, Retracemode%, Source$, Scratr$, StringDisp%, _
  6.   '     DestSeg%, Disp%)
  7.   '   where:
  8.   '     Numbytes% is the number of bytes that will be written to the screen.
  9.   '     If Retracemode% <> 0, retrace is checked before writing to video
  10.   '     memory to avoid snow.
  11.   '     Source$ is the text string that will be written.  It must be
  12.   '       NumBytes% + StringDisp% in length or longer.
  13.   '     Scratr$ is the string containing the attribute bytes.  Each character
  14.   '       of Source$ is mapped to each character of Scratr$.
  15.   '     StringDisp% is the displacement from the start of Source$ and
  16.   '       Scratr$ of the text to be written to the screen.
  17.   '     DestSeg% is the segment address of the video ram.
  18.   '     Disp% is the screen starting location to write to in terms of the
  19.   '       number of characters displacement from the start of the screen video
  20.   '       ram.  Thus the first row - first column is 0, second row - first
  21.   '       column is 80, etc.
  22.   '
  23.  
  24.   'This version is for size-displacement order of string descriptors
  25.  
  26.   $INLINE &H55, &H8B, &HEC, &H6 , &H1E, &H8B, &H16, &H0 , &H0 , &HC5
  27.   $INLINE &H76, &HA , &H8E, &H4 , &HC5, &H76, &H6 , &H8B, &H3C, &HC5
  28.   $INLINE &H76, &H1A, &H8B, &H4 , &H50, &HC5, &H76, &HE , &H8B, &H4
  29.   $INLINE &HC5, &H76, &H12, &H8B, &H5C, &H2 , &H3 , &HD8, &HC5, &H76
  30.   $INLINE &H1E, &H8B, &HC , &HC5, &H76, &H16, &H8B, &H74, &H2 , &H3
  31.   $INLINE &HF0, &H58, &HD1, &HE7, &HFC, &H8E, &HDA, &H3D, &H0 , &H0
  32.   $INLINE &H74, &H25, &HBA, &HDA, &H3 , &HAC, &H8B, &HEE, &H8B, &HF3
  33.   $INLINE &H8A, &H24, &H43, &H8B, &HF5, &H8B, &HE8, &HB4, &H9 , &HEC
  34.   $INLINE &HD0, &HD8, &H72, &HFB, &HFA, &HEC, &H22, &HC4, &H74, &HFB
  35.   $INLINE &H8B, &HC5, &HAB, &HFB, &HE2, &HE1, &HEB, &HE , &H90, &HAC
  36.   $INLINE &H8B, &HEE, &H8B, &HF3, &H8A, &H24, &H8B, &HF5, &H43, &HAB
  37.   $INLINE &HE2, &HF3, &H1F, &H7 , &H5D
  38.  
  39. 'cseg    segment     para public 'code'
  40. '        assume      nothing
  41. '        assume      cs:cseg
  42. '
  43. 'WriteVid proc    far
  44. '
  45. '   push bp
  46. '   mov  bp,sp
  47. '   push es
  48. '   push ds
  49. '   mov  dx,ds:0    ;save string segment
  50. '   lds  si,[bp+10]
  51. '   mov  es,[si]    ;dest seg into ES
  52. '   lds  si,[bp+6]
  53. '   mov  di,[si]    ;dest disp into DI
  54. '   lds  si,[bp+26]
  55. '   mov  ax,[si]    ;Retracemode% to AX
  56. '   push ax
  57. '   lds  si,[bp+14]
  58. '   mov  ax,[si]    ;Stringdisp%
  59. '   lds  si,[bp+18]
  60. '   mov  bx,[si+2]  ;addr of attr string
  61. '   add  bx,ax      ;add string displacement
  62. '   lds  si,[bp+30]
  63. '   mov  cx,[si]    ;Numbytes% to CX
  64. '   lds  si,[bp+22]
  65. '   mov  si,[si+2]  ;source ptr to SI
  66. '   add  si,ax      ;add string displacement
  67. '   pop  ax
  68. '   shl  di,1       ;displ * 2 for dest
  69. '   cld             ;string direction forwd
  70. '   mov  ds,dx      ;set string segment
  71. '   cmp  ax,0
  72. '   jz   h          ;not retracemode
  73. '   mov  dx,03dah   ;DX to CGA status port
  74. 'z: lodsb           ;grab a video byte
  75. '   mov  bp,si
  76. '   mov  si,bx
  77. '   mov  ah,[si]
  78. '   inc  bx
  79. '   mov  si,bp
  80. '   mov  bp,ax      ;save it
  81. '   mov  ah,9       ;save retrace mask
  82. 'o: in   al,dx      ;get 6845 status
  83. '   rcr  al,1       ;check horiz retrace
  84. '   jb   o          ;loop if in horiz retr:
  85. '                   ; Prevents starting in
  86. '                   ; mid-retr, since there
  87. '                   ; is enough time for 1
  88. '                   ; & only 1 STOSW during
  89. '                   ; horizontal retrace.
  90. '   cli             ;no ints, critical sect
  91. 't: in   al,dx      ;get 6845 status
  92. '   and  al,ah      ;chk horiz & vert retr:
  93. '                   ; If the video board
  94. '                   ; doesn't report horiz
  95. '                   ; retr while in vert,
  96. '                   ; retr, this will allow
  97. '                   ; several chars to be
  98. '                   ; stuffed in during
  99. '                   ; vertical retrace.
  100. '   jz   t          ;loop if 0
  101. '   mov  ax,bp      ;get the video byte
  102. '   stosw           ;store the video word
  103. '   sti             ;allow interrupts
  104. '   loop z          ;go do next word
  105. '   jmp  f
  106. 'h: lodsb           ;grab a video byte.
  107. '   mov  bp,si
  108. '   mov  si,bx
  109. '   mov  ah,[si]
  110. '   mov  si,bp
  111. '   inc  bx
  112. '   stosw           ;video word into screen
  113. '   loop h          ;repeat for len in CX
  114. 'f: pop ds
  115. '   pop es
  116. '   pop bp
  117. '
  118. 'WriteVid        endp
  119. '
  120. 'cseg        ends
  121. '            end
  122.  
  123. '  This version is for displacement-size order of string descriptors
  124. '
  125. '  $INLINE &H55, &H8B, &HEC, &H6 , &H1E, &H8B, &H16, &H0 , &H0 , &HC5
  126. '  $INLINE &H76, &HA , &H8E, &H4 , &HC5, &H76, &H6 , &H8B, &H3C, &HC5
  127. '  $INLINE &H76, &H1A, &H8B, &H4 , &H50, &HC5, &H76, &HE , &H8B, &H4
  128. '  $INLINE &HC5, &H76, &H12, &H8B, &H1C, &H3 , &HD8, &HC5, &H76, &H1E
  129. '  $INLINE &H8B, &HC , &HC5, &H76, &H16, &H8B, &H34, &H3 , &HF0, &H58
  130. '  $INLINE &HD1, &HE7, &HFC, &H8E, &HDA, &H3D, &H0 , &H0 , &H74, &H25
  131. '  $INLINE &HBA, &HDA, &H3 , &HAC, &H8B, &HEE, &H8B, &HF3, &H8A, &H24
  132. '  $INLINE &H43, &H8B, &HF5, &H8B, &HE8, &HB4, &H9 , &HEC, &HD0, &HD8
  133. '  $INLINE &H72, &HFB, &HFA, &HEC, &H22, &HC4, &H74, &HFB, &H8B, &HC5
  134. '  $INLINE &HAB, &HFB, &HE2, &HE1, &HEB, &HE , &H90, &HAC, &H8B, &HEE
  135. '  $INLINE &H8B, &HF3, &H8A, &H24, &H8B, &HF5, &H43, &HAB, &HE2, &HF3
  136. '  $INLINE &H1F, &H7 , &H5D
  137. '
  138. 'cseg    segment     para public 'code'
  139. '        assume      nothing
  140. '        assume      cs:cseg
  141. '
  142. 'WriteVid proc    far
  143. '
  144. '   push bp
  145. '   mov  bp,sp
  146. '   push es
  147. '   push ds
  148. '   mov  dx,ds:0    ;save string segment
  149. '   lds  si,[bp+10]
  150. '   mov  es,[si]    ;dest seg into ES
  151. '   lds  si,[bp+6]
  152. '   mov  di,[si]    ;dest disp into DI
  153. '   lds  si,[bp+26]
  154. '   mov  ax,[si]    ;Retracemode% to AX
  155. '   push ax
  156. '   lds  si,[bp+14]
  157. '   mov  ax,[si]    ;Stringdisp%
  158. '   lds  si,[bp+18]
  159. '   mov  bx,[si]    ;addr of attr string
  160. '   add  bx,ax      ;add string displacement
  161. '   lds  si,[bp+30]
  162. '   mov  cx,[si]    ;Numbytes% to CX
  163. '   lds  si,[bp+22]
  164. '   mov  si,[si]    ;source ptr to SI
  165. '   add  si,ax      ;add string displacement
  166. '   pop  ax
  167. '   shl  di,1       ;displ * 2 for dest
  168. '   cld             ;string direction forwd
  169. '   mov  ds,dx      ;set string segment
  170. '   cmp  ax,0
  171. '   jz   h          ;not retracemode
  172. '   mov  dx,03dah   ;DX to CGA status port
  173. 'z: lodsb           ;grab a video byte
  174. '   mov  bp,si
  175. '   mov  si,bx
  176. '   mov  ah,[si]
  177. '   inc  bx
  178. '   mov  si,bp
  179. '   mov  bp,ax      ;save it
  180. '   mov  ah,9       ;save retrace mask
  181. 'o: in   al,dx      ;get 6845 status
  182. '   rcr  al,1       ;check horiz retrace
  183. '   jb   o          ;loop if in horiz retr:
  184. '                   ; Prevents starting in
  185. '                   ; mid-retr, since there
  186. '                   ; is enough time for 1
  187. '                   ; & only 1 STOSW during
  188. '                   ; horizontal retrace.
  189. '   cli             ;no ints, critical sect
  190. 't: in   al,dx      ;get 6845 status
  191. '   and  al,ah      ;chk horiz & vert retr:
  192. '                   ; If the video board
  193. '                   ; doesn't report horiz
  194. '                   ; retr while in vert,
  195. '                   ; retr, this will allow
  196. '                   ; several chars to be
  197. '                   ; stuffed in during
  198. '                   ; vertical retrace.
  199. '   jz   t          ;loop if 0
  200. '   mov  ax,bp      ;get the video byte
  201. '   stosw           ;store the video word
  202. '   sti             ;allow interrupts
  203. '   loop z          ;go do next word
  204. '   jmp  f
  205. 'h: lodsb           ;grab a video byte.
  206. '   mov  bp,si
  207. '   mov  si,bx
  208. '   mov  ah,[si]
  209. '   mov  si,bp
  210. '   inc  bx
  211. '   stosw           ;video word into screen
  212. '   loop h          ;repeat for len in CX
  213. 'f: pop ds
  214. '   pop es
  215. '   pop bp
  216. '
  217. 'WriteVid        endp
  218. '
  219. 'cseg        ends
  220. '            end
  221.  
  222. END SUB 'WriteVid
  223.  
  224.  
  225.  
  226. SUB ReadVid INLINE
  227.   '
  228.   ' Move bytes from video memory preventing screen flicker and snow.
  229.   ' Turbo Basic calling sequence:
  230.   '   call ReadVid _
  231.   '     (NumBytes%, Retracemode%, Text$, Attr$, StringDisp%, SourceSeg%, Disp%)
  232.   '   where:
  233.   '     NumBytes% is the number of bytes that will be read from the screen.
  234.   '     If Retracemode% <> 0, retrace is checked before reading from video
  235.   '       memory to avoid snow.
  236.   '     Text$ is the text string that will be contain the characters read from
  237.   '       the screen. It must be preset to NumBytes% + StringDisp% in length
  238.   '       or longer.
  239.   '     Attr$ is the string that will contain the attribute bytes.  Each
  240.   '       character of Text$ will be mapped to each character of Scratr$.
  241.   '       It must be preset to Numbytes% + StringDisp% in length or longer.
  242.   '     StringDisp% is the displacement from the start of the Text$ and Attr$
  243.   '       string to begin placing the characters read from the screen.
  244.   '     SourceSeg% is the segment address of the video ram.
  245.   '     Disp% is the screen starting location to read from in terms of the
  246.   '       number of characters displacement from the start of the screen video
  247.   '       ram.  Thus the first row - first column is 0, second row - first
  248.   '       column is 80, etc.
  249.   '
  250.  
  251.   'This version is for size-displacement order of string descriptors
  252.  
  253.   $INLINE &H55, &H8B, &HEC, &H1E, &H6 , &HBA, &HDA, &H3 , &HA1, &H0
  254.   $INLINE &H0 , &H8E, &HC0, &HC5, &H76, &H1A, &H8B, &H4 , &HC5, &H76
  255.   $INLINE &H1E, &H8B, &HC , &HC5, &H76, &H12, &H8B, &H5C, &H2 , &HC5
  256.   $INLINE &H76, &HA , &H8E, &H1C, &H6 , &H50, &HC4, &H7E, &HE , &H26
  257.   $INLINE &H8B, &H5 , &H3 , &HD8, &HC4, &H7E, &H6 , &H26, &H8B, &H35
  258.   $INLINE &HC4, &H7E, &H16, &H26, &H8B, &H7D, &H2 , &H3 , &HF8, &H58
  259.   $INLINE &H7 , &HD1, &HE6, &HFC, &H3D, &H0 , &H0 , &H74, &H23, &HB4
  260.   $INLINE &H9 , &HEC, &HD0, &HD8, &H72, &HFB, &HFA, &HEC, &H22, &HC4
  261.   $INLINE &H74, &HFB, &HAD, &HFB, &H26, &H88, &H5 , &H8B, &HEF, &H8B
  262.   $INLINE &HFB, &H26, &H88, &H25, &H8B, &HFD, &H43, &H47, &HE2, &HE1
  263.   $INLINE &H3B, &HC0, &H74, &H11, &HAD, &H26, &H88, &H5 , &H8B, &HEF
  264.   $INLINE &H8B, &HFB, &H26, &H88, &H25, &H8B, &HFD, &H43, &H47, &HE2
  265.   $INLINE &HEF, &H7 , &H1F, &H5D
  266.  
  267. 'cseg    segment     para public 'code'
  268. '        assume      nothing
  269. '        assume      cs:cseg
  270. '
  271. 'ReadVid  proc far
  272. '    push bp
  273. '    mov  bp,sp
  274. '    push ds
  275. '    push es
  276. '    mov  dx,03dah   ;point DX to CGA status port
  277. '    mov  ax,ds:0    ;string segment
  278. '    mov  es,ax      ; to ES
  279. '    lds  si,[bp+26] ;Retracemode%
  280. '    mov  ax,[si]    ; to AX
  281. '    lds  si,[bp+30] ;NumBytes%
  282. '    mov  cx,[si]    ; to CX
  283. '    lds  si,[bp+18] ;disp of attr str
  284. '    mov  bx,[si+2]  ; to BX
  285. '    lds  si,[bp+10] ;Sourceseg%
  286. '    mov  ds,[si]    ; to DS
  287. '    push es         ;
  288. '    push ax
  289. '    les  di,[bp+14]
  290. '    mov  ax,es:[di] ;Stringdisp%
  291. '    add  bx,ax      ;add string displacement
  292. '    les  di,[bp+6]  ;Disp%
  293. '    mov  si,es:[di] ; to SI
  294. '    les  di,[bp+22] ;disp of text str
  295. '    mov  di,es:[di+2] ; to DI
  296. '    add  di,ax      ;add string displacement
  297. '    pop  ax
  298. '    pop  es         ;
  299. '    shl  si,1       ;displacement * 2 for source
  300. '    cld             ;set string direction to forward
  301. '    cmp  ax,0
  302. '    jz   .7         ;not retmode, use simpler routine
  303. '.5: mov  ah,9       ;move horiz. + vertical retrace
  304. '                    ; mask to fast storage
  305. '.9: in   al,dx      ;get 6845 status
  306. '    rcr  al,1       ;check horizontal retrace
  307. '    jb   .9         ;loop if in horizontal retrace:
  308. '                    ; this prevents starting in mid
  309. '                    ; retrace, since there is enough
  310. '                    ; time for 1 and only 1 STOSW
  311. '                    ; during horizontal retrace
  312. '    cli             ;no ints during critical section
  313. '.6: in   al,dx      ;get 6845 status
  314. '    and  al,ah      ;check for both kinds of retrace:
  315. '                    ; if the video board does not
  316. '                    ; report horizontal retrace while
  317. '                    ; in vertical retrace, this will
  318. '                    ; allow several characters to be
  319. '                    ; stuffed in during vertical
  320. '                    ; retrace
  321. '    jz   .6         ;loop if zero. else clear to
  322. '                    ; access video ram
  323. '    lodsw           ;grab char + attribute).
  324. '    sti             ;allow interrupts
  325. '    mov  es:[di],al ;get character
  326. '    mov  bp,di      ;save pointer to text string
  327. '    mov  di,bx      ;get pointer to screen attribute
  328. '    mov  es:[di],ah ;get screen attribute
  329. '    mov  di,bp      ;restore pointer to text string
  330. '    inc  bx         ;increment ptr to scr attribute
  331. '    inc  di         ;increment pointer to text string
  332. '    loop .5         ;do cx (numbytes) times
  333. '    cmp  ax,ax      ;MASM V4 complains if just:
  334. '    jz  .8          ;  jmp .8
  335. '.7: lodsw           ;grab character + attribute
  336. '    mov  es:[di],al ;get character
  337. '    mov  bp,di      ;save pointer to text string
  338. '    mov  di,bx      ;get pointer to screen attribute
  339. '    mov  es:[di],ah ;get screen attribute
  340. '    mov  di,bp      ;restor pointer to text string
  341. '    inc  bx         ;increment ptr to scr attribute
  342. '    inc  di         ;increment pointer to text string
  343. '    loop .7         ;do cx (numbytes) times
  344. '.8: pop  es
  345. '    pop  ds
  346. '    pop  bp
  347. '
  348. '
  349. 'ReadVid endp
  350. '
  351. 'cseg        ends
  352. '            end
  353.  
  354. '  This version is for displacement-size order of string descriptors
  355. '
  356. '  $INLINE &H55, &H8B, &HEC, &H1E, &H6 , &HBA, &HDA, &H3 , &HA1, &H0
  357. '  $INLINE &H0 , &H8E, &HC0, &HC5, &H76, &H1A, &H8B, &H4 , &HC5, &H76
  358. '  $INLINE &H1E, &H8B, &HC , &HC5, &H76, &H12, &H8B, &H1C, &HC5, &H76
  359. '  $INLINE &HA , &H8E, &H1C, &H6 , &H50, &HC4, &H7E, &HE , &H26, &H8B
  360. '  $INLINE &H5 , &H3 , &HD8, &HC4, &H7E, &H6 , &H26, &H8B, &H35, &HC4
  361. '  $INLINE &H7E, &H16, &H26, &H8B, &H3D, &H3 , &HF8, &H58, &H7 , &HD1
  362. '  $INLINE &HE6, &HFC, &H3D, &H0 , &H0 , &H74, &H23, &HB4, &H9 , &HEC
  363. '  $INLINE &HD0, &HD8, &H72, &HFB, &HFA, &HEC, &H22, &HC4, &H74, &HFB
  364. '  $INLINE &HAD, &HFB, &H26, &H88, &H5 , &H8B, &HEF, &H8B, &HFB, &H26
  365. '  $INLINE &H88, &H25, &H8B, &HFD, &H43, &H47, &HE2, &HE1, &H3B, &HC0
  366. '  $INLINE &H74, &H11, &HAD, &H26, &H88, &H5 , &H8B, &HEF, &H8B, &HFB
  367. '  $INLINE &H26, &H88, &H25, &H8B, &HFD, &H43, &H47, &HE2, &HEF, &H7
  368. '  $INLINE &H1F, &H5D
  369. '
  370. 'cseg    segment     para public 'code'
  371. '        assume      nothing
  372. '        assume      cs:cseg
  373. '
  374. 'ReadVid  proc far
  375. '    push bp
  376. '    mov  bp,sp
  377. '    push ds
  378. '    push es
  379. '    mov  dx,03dah   ;point DX to CGA status port
  380. '    mov  ax,ds:0    ;string segment
  381. '    mov  es,ax      ; to ES
  382. '    lds  si,[bp+26] ;Retracemode%
  383. '    mov  ax,[si]    ; to AX
  384. '    lds  si,[bp+30] ;NumBytes%
  385. '    mov  cx,[si]    ; to CX
  386. '    lds  si,[bp+18] ;disp of attr str
  387. '    mov  bx,[si]    ; to BX
  388. '    lds  si,[bp+10] ;Sourceseg%
  389. '    mov  ds,[si]    ; to DS
  390. '    push es         ;
  391. '    push ax
  392. '    les  di,[bp+14]
  393. '    mov  ax,es:[di] ;Stringdisp%
  394. '    add  bx,ax      ;add string displacement
  395. '    les  di,[bp+6]  ;Disp%
  396. '    mov  si,es:[di] ; to SI
  397. '    les  di,[bp+22] ;disp of text str
  398. '    mov  di,es:[di] ; to DI
  399. '    add  di,ax      ;add string displacement
  400. '    pop  ax
  401. '    pop  es         ;
  402. '    shl  si,1       ;displacement * 2 for source
  403. '    cld             ;set string direction to forward
  404. '    cmp  ax,0
  405. '    jz   .7         ;not retmode, use simpler routine
  406. '.5: mov  ah,9       ;move horiz. + vertical retrace
  407. '                    ; mask to fast storage
  408. '.9: in   al,dx      ;get 6845 status
  409. '    rcr  al,1       ;check horizontal retrace
  410. '    jb   .9         ;loop if in horizontal retrace:
  411. '                    ; this prevents starting in mid
  412. '                    ; retrace, since there is enough
  413. '                    ; time for 1 and only 1 STOSW
  414. '                    ; during horizontal retrace
  415. '    cli             ;no ints during critical section
  416. '.6: in   al,dx      ;get 6845 status
  417. '    and  al,ah      ;check for both kinds of retrace:
  418. '                    ; if the video board does not
  419. '                    ; report horizontal retrace while
  420. '                    ; in vertical retrace, this will
  421. '                    ; allow several characters to be
  422. '                    ; stuffed in during vertical
  423. '                    ; retrace
  424. '    jz   .6         ;loop if zero. else clear to
  425. '                    ; access video ram
  426. '    lodsw           ;grab char + attribute).
  427. '    sti             ;allow interrupts
  428. '    mov  es:[di],al ;get character
  429. '    mov  bp,di      ;save pointer to text string
  430. '    mov  di,bx      ;get pointer to screen attribute
  431. '    mov  es:[di],ah ;get screen attribute
  432. '    mov  di,bp      ;restore pointer to text string
  433. '    inc  bx         ;increment ptr to scr attribute
  434. '    inc  di         ;increment pointer to text string
  435. '    loop .5         ;do cx (numbytes) times
  436. '    cmp  ax,ax      ;MASM V4 complains if just:
  437. '    jz  .8          ;  jmp .8
  438. '.7: lodsw           ;grab character + attribute
  439. '    mov  es:[di],al ;get character
  440. '    mov  bp,di      ;save pointer to text string
  441. '    mov  di,bx      ;get pointer to screen attribute
  442. '    mov  es:[di],ah ;get screen attribute
  443. '    mov  di,bp      ;restor pointer to text string
  444. '    inc  bx         ;increment ptr to scr attribute
  445. '    inc  di         ;increment pointer to text string
  446. '    loop .7         ;do cx (numbytes) times
  447. '.8: pop  es
  448. '    pop  ds
  449. '    pop  bp
  450. '
  451. '
  452. 'ReadVid endp
  453. '
  454. 'cseg        ends
  455. '            end
  456.  
  457. END SUB 'ReadVid